/*
 * Created on Jul 23, 2005
 *
 */
package org.mushroomdb.executionplan;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * @author Matu
 *
 */
public class ExecutionPlanElementImpl implements ExecutionPlanElement {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2173600204721314534L;
	
	private String name;
	private List<String> attributes;
	private List<ExecutionPlanElement> children;
	
	/**
	 * Constructor sin atributos.
	 * @param name
	 */
	public ExecutionPlanElementImpl(String name) {
		this.name = name;
		this.children = new LinkedList<ExecutionPlanElement>();
	}
	
	/**
	 * Constructor.
	 * @param name
	 * @param attributes
	 */
	public ExecutionPlanElementImpl(String name, List<String> attributes) {
		this.name = name;
		this.attributes = attributes;
		this.children = new LinkedList<ExecutionPlanElement>();
	}
	
	/**
	 * Agrega un elemento hijo.
	 * @param executionPlanElement
	 */
	public void addChild(ExecutionPlanElement executionPlanElement) {
		this.children.add(executionPlanElement);
	}

	/**
	 * @see org.mushroomdb.executionplan.ExecutionPlanElement#getName()
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @see org.mushroomdb.executionplan.ExecutionPlanElement#getAttributes()
	 */
	public Iterator<String> getAttributes() {
		if (this.attributes == null) {
			return new Iterator<String>() {
				public boolean hasNext() { return false; }
				public String next() { throw new NoSuchElementException(); }
				public void remove() { throw new UnsupportedOperationException(); }
			};
		} else {
			return this.attributes.iterator();
		}
	}

	/**
	 * @see org.mushroomdb.executionplan.ExecutionPlanElement#getChildren()
	 */
	public Iterator<ExecutionPlanElement> getChildren() {
		return this.children.iterator();
	}

}
